package rdgl.compiler;

/**
 * 
 * @author Navid
 *
 */
public class RandomData {

	private DataType type;
	private DataList dataList;
	private String value;
	
	/**
	 * 
	 *
	 */
	public RandomData() {
		this.dataList = new DataList();
		this.value = new String();
	}
	
	/**
	 * 
	 * @param type
	 * @param dataList
	 */
	public RandomData(DataType type, DataList dataList) {
		this.type = type;
		this.dataList = dataList;
		this.value = new String();
	}
	
	/**
	 * 
	 * @param type
	 */
	public void setType(DataType type) {
		this.type = type;
	}
	
	/**
	 * 
	 * @param dataList
	 */
	public void setDataList(DataList dataList) {
		this.dataList = dataList;
	}
	
	/**
	 * Returns the current value of the expression. Primarily used
	 * as a test hook for JUnit tests.
	 * @return
	 */
	public String getValue() {
		return this.value;
	}
	
	/**
	 * Outputs the current value of the expression after it has been
	 * randomly generated.
	 *
	 */
	public void print() {
		this.calculate();
		System.out.print(this.value);
	}
	
	/**
	 * 
	 *
	 */
	private void calculate() {
		int index = Integer.parseInt(Engine.getRandomNumber(0, this.dataList.getSize() - 1));
		if (this.type == DataType.Enum) {
			this.value += this.dataList.get(index);  
		} else {
			int length = Integer.parseInt(this.dataList.get(index));
			if(this.type == DataType.Number) {
				this.value += Engine.getRandomNumber(length);
			} else if (this.type == DataType.Letter) {
				this.value += Engine.getRandomCharacter(length);
			} else if (this.type == DataType.AlphaNumeric) {
				this.value += Engine.getRandomAlphaNumeric(length);
			} else if (this.type == DataType.Symbol) {
				this.value += Engine.getRandomSymbol(length);
			} else if (this.type == DataType.Any) {
				this.value += Engine.getRandomString(length);
			}
		}
	}
}
